home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Authority.sea / XML Authority / Required / ccs_util.jar / test / textui / TestRunner.class (.txt) next >
Encoding:
Java Class File  |  1999-12-09  |  2.7 KB  |  79 lines

  1. package test.textui;
  2.  
  3. import java.lang.reflect.Method;
  4. import test.framework.Test;
  5.  
  6. public class TestRunner {
  7.    private static boolean fWait;
  8.  
  9.    public static void main(String[] argv) {
  10.       String testCase = "";
  11.  
  12.       for(int i = 0; i < argv.length; ++i) {
  13.          if (argv[i].equals("-wait")) {
  14.             fWait = true;
  15.          } else {
  16.             testCase = argv[i];
  17.          }
  18.       }
  19.  
  20.       if (testCase.equals("")) {
  21.          System.out.println("Usage: driver [-wait] testCaseName, where name is the name of the TestCase class");
  22.          System.exit(0);
  23.       }
  24.  
  25.       try {
  26.          Class testClass = null;
  27.          Method suiteMethod = null;
  28.          Test suite = null;
  29.  
  30.          try {
  31.             testClass = Class.forName(testCase);
  32.          } catch (Exception var8) {
  33.             System.out.println("Suite class \"" + testCase + "\" not found");
  34.             return;
  35.          }
  36.  
  37.          try {
  38.             suiteMethod = testClass.getMethod("suite");
  39.          } catch (Exception var7) {
  40.             System.out.println("The suite class should have a method named \"suite()\"");
  41.             return;
  42.          }
  43.  
  44.          try {
  45.             suite = (Test)suiteMethod.invoke((Object)null);
  46.          } catch (Exception var6) {
  47.             System.out.println("Could not invoke the suite() method");
  48.             return;
  49.          }
  50.  
  51.          run(suite);
  52.       } catch (Exception var9) {
  53.          System.out.println("Could not create and run test suite");
  54.       }
  55.  
  56.    }
  57.  
  58.    public static void run(Test suite) {
  59.       TextTestResult result = new TextTestResult();
  60.       long startTime = System.currentTimeMillis();
  61.       suite.run(result);
  62.       long endTime = System.currentTimeMillis();
  63.       long runTime = endTime - startTime;
  64.       System.out.println();
  65.       System.out.println("Time: " + runTime / 1000L + "." + runTime % 1000L);
  66.       result.print();
  67.       System.out.println();
  68.       if (fWait) {
  69.          System.out.println("<RETURN> to continue");
  70.  
  71.          try {
  72.             System.in.read();
  73.          } catch (Exception var8) {
  74.          }
  75.       }
  76.  
  77.    }
  78. }
  79.